//
//  PersonCustomCell.m
//  XMJJ_zml
//
//  Created by 杨何华 on 2025/5/13.
//

#import "PersonCustomCell.h"

@implementation PersonCustomCell
+ (NSString *)reuseIdentifier {
    return @"CustomCellIdentifier";
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    // 头像
    self.avatarImageView = [[UIImageView alloc] init];
    self.avatarImageView.layer.cornerRadius = 30;
    self.avatarImageView.clipsToBounds = YES;
    [self.contentView addSubview:self.avatarImageView];
    
    // 名称标签
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:self.nameLabel];
    self.nameLabel.textColor = kColorHEX(0x333333);

    
    self.nameLabel.text = @"张三";

    // 子标题标签
    self.subTitleLabel = [[UILabel alloc] init];
    self.subTitleLabel.font = [UIFont boldSystemFontOfSize:13];
    self.subTitleLabel.textColor = kColorHEX(0x3B5998);
    [self.contentView addSubview:self.subTitleLabel];
    self.subTitleLabel.text = @"张三的xxxx";

    // 进入主页按钮
    self.enterButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.enterButton setTitle:@"进入主页>" forState:UIControlStateNormal];
    self.enterButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.enterButton setTitleColor:kColorHEX(0x999999) forState:UIControlStateNormal];
    [self.contentView addSubview:self.enterButton];
    
    [self.enterButton addTarget:self action:@selector(goPersonMainPage) forControlEvents:UIControlEventTouchUpInside];

}
- (void)goPersonMainPage
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(goPersonMainPageAction:)]) {
        [self.delegate goPersonMainPageAction:self];
    }
}
- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat padding = 15;
    CGFloat avatarSize = 60;
    CGFloat buttonWidth = 100;
    
    // 布局头像
    self.avatarImageView.frame = CGRectMake(padding, (self.contentView.bounds.size.height - avatarSize) / 2, avatarSize, avatarSize);
    
    // 布局名称标签
    CGFloat nameX = CGRectGetMaxX(self.avatarImageView.frame) + padding;
    CGFloat nameWidth = self.contentView.bounds.size.width - nameX - buttonWidth - padding;
    self.nameLabel.frame = CGRectMake(nameX, (self.contentView.bounds.size.height - 18) / 2 - 10, nameWidth, 18);
    
    // 布局子标题标签
    CGFloat subTitleX = nameX;
    CGFloat subTitleWidth = nameWidth;
    self.subTitleLabel.frame = CGRectMake(subTitleX, CGRectGetMaxY(self.nameLabel.frame) + 5, subTitleWidth, 14);
    
    // 布局进入主页按钮
    CGFloat buttonX = self.contentView.bounds.size.width - buttonWidth - padding;
    self.enterButton.frame = CGRectMake(buttonX, (self.contentView.bounds.size.height - 16) / 2, buttonWidth, 16);
}

@end
